<?php
// compare version
if (version_compare(PHP_VERSION, '5.1.2', '<'))
{
    echo 'It is requireed at least PHP 5.1.2';
    exit();
}

ob_start();

// Define NUO
defined('NUO') OR define('NUO', 1);

// set system default timezone.
date_default_timezone_set('UTC');

// define ROOT PATH
defined('ROOT_PATH') OR define('ROOT_PATH', realpath(dirname(dirname(__FILE__))));

defined('PUBLIC_PATH') or define('PUBLIC_PATH', ROOT_PATH . '/public');

// define application path
defined('APPLICATION_PATH') OR define('APPLICATION_PATH', ROOT_PATH . '/application');

// define ROOT PATH
defined('INCLUDE_PATH') OR define('INCLUDE_PATH', ROOT_PATH . '/include');

// define static path
defined('STATIC_PATH') OR define('STATIC_PATH', ROOT_PATH . '/static');

// define library path
defined('LIBRARY_PATH') OR define('LIBRARY_PATH', ROOT_PATH . '/library');

// define setting path
defined('SETTING_PATH') OR define('SETTING_PATH', APPLICATION_PATH . '/settings');

// define install path
defined('INSTALL_PATH') OR define('INSTALL_PATH', ROOT_PATH . '/install');

// load default config
$config = array();

if (file_exists($filename = SETTING_PATH . '/bootstrap.php'))
{
    $config = (array)(
    require_once $filename);
}

if (empty($config))
{
    die("configuration file does not exist");
}

// define default locale
defined('NUO_DEFAULT_LOCALE') OR define('NUO_DEFAULT_LOCALE', $config['default_locale']);

// define default locale
defined('NUO_DEFAULT_LANGUAGE') OR define('NUO_DEFAULT_LANGUAGE', $config['default_language']);

// define default locale
defined('NUO_DEFAULT_TIMEZONE') OR define('NUO_DEFAULT_TIMEZONE', $config['default_timezone']);

// Define application environment
defined('APPLICATION_ENV') OR define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : $config['application_env']));

// define error silence mode
defined('NUO_ERROR_SILENCE') OR define('NUO_ERROR_SILENCE', $config['error_silence_mode']);

// define temporary path
$temp_path = empty($config['temporary_path']) ? (ROOT_PATH . '/temp') : $config['temporary_path'];
defined('TEMP_PATH') OR define('TEMP_PATH', $temp_path);

// define cache path
defined('CACHE_PATH') OR define('CACHE_PATH', TEMP_PATH . '/cache');

// define session path
defined('SESSION_PATH') OR define('SESSION_PATH', TEMP_PATH . '/session');

// define log path
$log_path = empty($config['log_path']) ? (ROOT_PATH . '/temp/log') : $config['log_path'];
defined('LOG_PATH') OR define('LOG_PATH', $log_path);

// define error reporting mode
defined('NUO_ERROR_REPORTING') OR define('NUO_ERROR_REPORTING', $config['error_reproting']);

ini_set('error_reporting', NUO_ERROR_REPORTING);

ini_set('display_startup_errors', $config['display_startup_errors']);

ini_set('display_errors', $config['display_errors']);
header('Content-Type','text/html;charset=utf-8');

if (function_exists('mb_internal_encoding'))
{
    mb_internal_encoding("UTF-8");
	
}

if (function_exists('iconv_set_encoding'))
{
    // Not sure if we want to do all of these
    iconv_set_encoding("input_encoding", "UTF-8");
    iconv_set_encoding("output_encoding", "UTF-8");
    iconv_set_encoding("internal_encoding", "UTF-8");
}

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(LIBRARY_PATH),
    get_include_path(),
)));



/** Zend_Application */
require_once LIBRARY_PATH . '/Nuo/Nuo.php';
require_once 'Zend/Loader/Autoloader.php';
require_once 'Zend/Application.php';

$loader = Zend_Loader_Autoloader::getInstance();

$loader -> registerNamespace(array(
    'Nuo',
    'Zend'
));

spl_autoload_register(array(
    'Nuo',
    'autoload'
));
